package zuoye_4_14;

import java.util.concurrent.ArrayBlockingQueue;

public class Foodie extends Thread {
	private ArrayBlockingQueue<String> abq;
	private static final int CONSUME_SIZE = 5;
	
	public Foodie(ArrayBlockingQueue<String> abq) {
		super();
		this.abq = abq;
	}

	@Override
	public void run() {
		while(true){
			try {
				synchronized(abq) {
					while(abq.size() < CONSUME_SIZE) {
						abq.wait();
					}
					for(int i = 0; i < CONSUME_SIZE; i++) {
						Foodie.sleep(500);
						String take = abq.take();
						System.out.println("消费了"+"1个"+take);
					}
					abq.notifyAll();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
}

